Desktop Shorcuts

by Gordon Rahman

Home

API Translator

Window Help

Communication

Slider Control

Desktop Shortcuts

Quick Visual Designer

Rules for Code

DATA and Arrays

Easy Polygon

Triangle Draw

Control a Sprite

Shell to DOS

Morse Code

Batch Files

Multicolumn Listbox

Newsletter help

Index


How to create a shortcut on the desktop with Windows XP.

The program SHORTCUT.EXE is needed.

Some years ago there was a problem creating shortcuts with LB. The community found a work around for this problem. Nowadays we have LB4. Of course there are no problems anymore, because this is LB4.

Here is my review of the history.

Alyce told me that in fact, a member of the yahoo group found some code in another language that used the recent menu to make shortcuts and he asked for someone to translate it. So, she translated it and it appeared to work. Brent quickly pointed out that the method was flawed and that the only way to do shortcuts properly required the use of COM objects, which aren't available in LB. Some people used it anyway, knowing that it was flawed.

The Com Interface needed to create a shortcut is IShellLink. If you like details, try http://www.bcbdev.com/faqs/faq79.htm for some explanation. Liberty Basic still doesn't handle Com Interfaces.

Luckily they (Microsoft) had provided a program to create shortcuts in MSDOS. Someone told me that the program came with W95. I didn't find it there. I found a program SHORTCUT.EXE at [http://www.OptimumX.com] Copyright 2000-2003 Marty List.

In the meantime, while I placed the question at a lot of places, I got numerous solutions. Some were in C++ and Visual Basic, yes even in Java. We had to wait for LB4 to enjoy this program, mainly because LB4 can hide the MSDOS window. Scott Bannon was the first to discover that it had become very easy for us now, thanks to LB4.

In essence you just have to run the program SHORTCUT.EXE with the new LB4 feature HIDE.

Now here is a little demo of the program. Again, there is nothing new here. I used routines made by others. I took a routine to find the desktop path. Then I created the shortcut and placed it at the desktop. Now it should be very easy to create a shortcut in Start Menu once you know the path to the Start Menu.

'Form created with the help of Freeform 3 v03-27-03
'Generated on Mar 06, 2004 at 16:52:12


[setup.main.Window]

    '-----Begin code for #main

    nomainwin
    WindowWidth = 550
    WindowHeight = 510
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)

    '-----Begin GUI objects code

    button #main.button1,"shortcut name",[shortcutClick], UL, 230, 67,175,25
    button #main.button2,"target file",[targetClick], UL, 230, 117,175,25
    button #main.button3,"get icon file",[iconClick], UL, 230, 167,175,25
    button #main.button4,"description for shortcut",[descriptionClick], UL, 230,217,175,25
    bmpbutton #main.button5,DefaultDir$ + "\bmp\ok.bmp",[button1Click], UL, 230, 267 

    '-----End GUI objects code

    open "CREATE a shortcut on desktop testprogram" for window as #main

    #main, "font ms_sans_serif 10"
    #main, "trapclose [quit.main]"

    #main.button1, "!font arial 12 bold"
    #main.button2, "!font arial 12 bold"

This first piece of code shouldn't give any problems as it was created with FREEFORM. Here is a picture of the window I made.

What follows is the DLL call to find the special folders like the desktop or the start menu. This routine was translated first by Alyce. Translation should be a piece of cake with the newly delivered programs at the API translators contest.

    CSIDL.DESKTOP = Hexdec("&H10")
    struct IDL,cb As long, abID As short
    desktop$ = GetSpecialfolder$(CSIDL.DESKTOP)

    discriptionName$ = "new shortcut"   'default text
    dfile$ = DefaultDir$
    wait

This is the main action. Desktop$ contains the special folders path. So a link file with the name shortcutName$ can be created at the desktop. Please place the program SHORTCUT.EXE in the Liberty directory (DefaultDir$) too.

[button1Click]   'Perform action for the button named 'button1'

shortcutName$ = desktop$ + "\" + shortcutName$ + ".lnk"

run dfile$ + "\shortcut.exe /F:" +_
chr$(34) + shortcutName$ +_
chr$(34) + " /A:C /T:" +_
chr$(34) + targetFileName$ +_
chr$(34) + " /P:" +_
chr$(34) + parameter$ +_
chr$(34) + " /W:" +_
chr$(34) + workdir$ +_
chr$(34) + " /R:"+_
chr$(34) + windowState$ +_
chr$(34) + " /I:" +_
chr$(34) + iconFileName$ +_
chr$(34) + " /D:" +_
chr$(34) + discriptionName$ +_
chr$(34), HIDE

    'Insert your own code here
    notice "Shortcut created"		 ' at ";desktop$
    wait

[quit.main] 'End the program
    close #main
    end

I took the next routine somewhere from the forum. I like it slightly better then the one that comes with LB (and Windows).

[shortcutClick]
    '------------------------prompt routine -------------
    WindowWidth = 330
    WindowHeight = 165

    BUTTON #main2.default, " OK ", [getit], UL, 250, 90, 30, 30

    statictext #main2.statictext1, "Type a name for your", 25, 25, 220, 20
    statictext #main2.statictext2, "shortcut and", 25, 50, 220, 20
    statictext #main2.statictext3, "press OK", 25, 75, 220, 20
    TextboxColor$ = "white"
    textbox #main2.textbox4, 20, 97, 180, 25

    open "Specify a name for the shortcut" for dialog_modal as #main2
    #main2, "font ms_sans_serif 10"
    #main2, "trapclose [quit.main2]"
    wait

[getit]
    #main2.textbox4, "!contents? shortcutName$"
    close #main2
    #main.button1, "!disable"
    wait

[quit.main2]
    close #main2
    wait
'----------------------------------------------------------

[targetClick]
    filedialog "Point at the Target file", "*.*", targetFileName$
    #main.button2, "!disable"
    wait

[iconClick]
    filedialog "Get an icon", "*.ico", iconFileName$
    wait

[descriptionClick]
    prompt"discription for the shortcut";discriptionName$
    wait


Function GetSpecialfolder$(CSIDL)
Open "shell32" For DLL As #sh
CallDLL #sh, "SHGetSpecialFolderLocation",_
0 As long, CSIDL As long, IDL As struct,_
ret As long

If ret=NOERROR Then
Path$ = Space$(512)
id=IDL.cb.struct

CallDLL #sh, "SHGetPathFromIDListA",_
id As long, Path$ As ptr, ret As long

Close #sh
GetSpecialfolder$ = Left$(Path$, Instr(Path$, Chr$(0)) - 1)

Else
GetSpecialfolder$ = "Error"
End If
End Function

This is how the program SHORTCUT.EXE works. To make a shortcut, you need to insert at least two parameters with the program SHORTCUT.EXE (the /F: and the /T: ) Here is the syntax of the command for shortcut.exe.

Shortcut.exe /F:filename /A:C|E|Q [/T:target] [/P:parameters] [/W:workingdir] [/R:runstyle] [/I:icon,index] [/H:hotkey] [/D:description]

/F:filename   : Specifies the .LNK or .URL shortcut file.
/A:action     : Defines the action to take (C=Create, E=Edit or Q=Query).
/T:target     : Defines the target path and file name the shortcut points to.
/P:parameters : Defines the command-line parameters to pass to the target.
/W:working dir: Defines the working directory the target starts with.
/R:run style  : Defines the window state (1=Normal, 3=Max, 7=Min).
/I:icon,index : Defines the icon and optional index (file.exe or file.exe,0).
/H:hotkey     : Defines the hotkey, a numeric value of the keyboard shortcut.
/D:description: Defines the description (or comment) for the shortcut.

F: Is where you can specify a name for your shortcut. Just any name will do. At first I was mistaken and took this for the target file.

T: Is the program Windows has to run when we click on our new shortcut.

To place the shortcut on the desktop we need to find the path to where the desktop directory resides. Now here is a piece of the work of Alyce, Brent and others in detail.

'----------------------------------------------------------------------
'Get the desktop path function

CSIDL.DESKTOP = Hexdec("&H10")	
struct IDL,cb As long, abID As short
desktop$ = GetSpecialfolder$(CSIDL.DESKTOP)


Home

API Translator

Window Help

Communication

Slider Control

Desktop Shortcuts

Quick Visual Designer

Rules for Code

DATA and Arrays

Easy Polygon

Triangle Draw

Control a Sprite

Shell to DOS

Morse Code

Batch Files

Multicolumn Listbox

Newsletter help

Index